package com.my.study.design.rule.support;

import com.my.study.design.rule.IRule;
import com.my.study.design.rule.RuleExecuteResult;

/**
 * 数据过滤抽象类
 *
 * @author: yidujun
 * @create: 2021/07/09 21:50
 */
public abstract class AbstractFilterRule implements IRule {

    @Override
    public RuleExecuteResult execute(Object obj) {
        boolean filter = filter(obj);
        return filter ? new RuleExecuteResult(RuleExecuteResult.EnumRuleResult.CONTINUE, obj)
                        : new RuleExecuteResult(RuleExecuteResult.EnumRuleResult.ABANDON, null);
    }

    /**
     * 数据过滤
     *
     * @param obj
     * @return
     */
    protected abstract boolean filter(Object obj);
}
